import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios';
// Vue.prototype.$axios = axios;

// axios.defaults.baseURL = '/api'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {

  },
  mutations: {
    login(state, payload) {
      const { userName, idactor, userNo } = payload;
      state.userName = userName;
      state.idactor = idactor;
      state.userNo = userNo;

    },
    discount(state, payload) {
      const { alldiscount } = payload;
      state.alldiscount = alldiscount;
    },
    full(state, payload) {
      const { border1, border2, border3, border_rule1, border_rule2, border_rule3 } = payload;
      state.border1 = border1;
      state.border2 = border2;
      state.border3 = border3;
      state.border_rule1 = border_rule1;
      state.border_rule2 = border_rule2;
      state.border_rule3 = border_rule3;
    }
  },
  actions: {
    async login({ commit }, payload) {
      const { gonghao, password } = payload;
      console.log(2333);
      await axios({
        url: "/login",
        method: "post",
        params: { gonghao: gonghao, password: password }
      })
        .then(res => {
          console.log("hhhhh");
          const { userName } = res.data.data;
          const { idactor } = res.data.data.actor;
          const { userNo } = res.data.data;



          // console.log(userName);
          commit("login", { userName, idactor, userNo })

        })
    },
    async discount({ commit }) {
      await axios({
        url: "/getAllDiscount",
        method: "get"
      }).then(res => {
        // console.log(res);
        const { alldiscount } = res.data;
        // console.log(alldiscount);
        commit("discount", { alldiscount })
      });
    },
    async full({ commit }) {
      await axios({
        url: "/getBorderDiscount",
        method: "get"
      }).then(res => {
        // console.log(res);
        const border1 = res.data[0].border;
        const border2 = res.data[1].border;
        const border3 = res.data[2].border;
        const border_rule1 = res.data[0].border_rule;
        const border_rule2 = res.data[1].border_rule;
        const border_rule3 = res.data[2].border_rule;
        // console.log(alldiscount);
        commit("full", { border1, border2, border3, border_rule1, border_rule2, border_rule3 })
      });
    },
  },
  modules: {
  }
})
